package com.whfc.wxmp.api.fse.controller;

import com.whfc.common.base.BaseController;
import com.whfc.common.result.*;
import com.whfc.wxmp.annotation.CurrentWxUser;
import com.whfc.fse.dto.FseLiftDTO;
import com.whfc.fse.dto.FseLiftDataDTO;
import com.whfc.fse.dto.FseLiftDataLogDTO;
import com.whfc.fse.dto.FseLiftFvsDeviceDTO;
import com.whfc.fse.param.*;
import com.whfc.fuum.entity.SysUser;
import com.whfc.fuum.entity.WxUser;
import com.whfc.wxmp.api.fse.service.WxFseLiftService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @DESCRIPTION 升降机管理
 * @AUTHOR GuoDong_Sun
 * @DATE 2020/4/10
 */
@RestController
@RequestMapping("/mp/api/lift")
public class WxFseLiftController extends BaseController {
    @Autowired
    private WxFseLiftService wxFseLiftService;


    @GetMapping("/list")
    public R<List<FseLiftDTO>> list(@CurrentWxUser WxUser user,
                       @RequestParam("deptId") Integer deptId) {
        logger.info("升降机列表,loginer:{},deptId:{},bindFlag:{}", user.getName(), deptId,null);
        List<FseLiftDTO> listData = wxFseLiftService.listV2(deptId);
        return R.success(listData);
    }

    @GetMapping("/fvs/list")
    public Result fvsList(@CurrentWxUser WxUser user,
                          @RequestParam("liftId") Integer liftId) {
        logger.info("获取视频监控列表，loginer:{},liftId:{}", user.getName(), liftId);
        List<FseLiftFvsDeviceDTO> fvsList = wxFseLiftService.fvsList(liftId);
        return ResultUtil.success(new ListData<>(fvsList));
    }


    @GetMapping("/latest")
    public Result latest(@CurrentWxUser WxUser user,
                         @RequestParam("liftId") Integer liftId) {
        logger.info("获取升降机及时数据,loginer:{},liftId:{}", user.getName(), liftId);
        List<FseLiftDataDTO> fseLiftDataList = wxFseLiftService.latest(liftId);
        return ResultUtil.success(new ListData<>(fseLiftDataList));
    }

    @GetMapping("/log")
    public Result log(@CurrentWxUser WxUser user,
                      @RequestParam("liftId") Integer liftId,
                      @DateTimeFormat(pattern = "yyyy-MM-dd") @RequestParam("date") Date date) {
        logger.info("获取升降机监控的历史数据,loginer:{},liftId:{},date:{}", user.getName(), liftId, date);
        ListData<FseLiftDataLogDTO> listData = wxFseLiftService.log(liftId, date);
        return ResultUtil.success(listData);
    }

}
